Forward Mac OS menu shortcut events to the right menu.
authorRichard Hult <richard@imendio.com>
Sun, 17 Jun 2007 20:36:26 +0000 (20:36 +0000)
committerRichard Hult <rhult@src.gnome.org>
Sun, 17 Jun 2007 20:36:26 +0000 (20:36 +0000)
2007-06-17  Richard Hult  <richard@imendio.com>

* gdk/quartz/gdkevents-quartz.c (gdk_event_translate): Forward
Mac OS menu shortcut events to the right menu.

svn path=/trunk/; revision=18178

ChangeLog
gdk/quartz/gdkevents-quartz.c

index 1d3f25bf1ebf9dfdf86ed9af6c7bcd2c2568e15f..01c9faa04c1c88abfa0669655104124601d1d034 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-06-17  Richard Hult  <richard@imendio.com>
+
+       * gdk/quartz/gdkevents-quartz.c (gdk_event_translate): Forward
+       Mac OS menu shortcut events to the right menu.
+
 2007-06-17  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkevents-quartz.c (gdk_event_translate)
index eecf1cd6f8273d565944ea8f9b6cd3dbe476349a..b1b39e092fb31299a1d110d865d09f7e39f57b36 100644 (file)
@@ -26,6 +26,7 @@
 #include <pthread.h>
 #include <unistd.h>
 
+#import <Cocoa/Cocoa.h>
 #include <Carbon/Carbon.h>
 
 #include "gdkscreen.h"
@@ -68,6 +69,18 @@ static void get_converted_window_coordinates    (GdkWindow *in_window,
                                                  gint      *out_y);
 static void append_event                        (GdkEvent  *event);
 
+/* A category that exposes the protected carbon event for an NSEvent. */
+@interface NSEvent (GdkQuartzNSEvent)
+- (void *)gdk_quartz_event_ref;
+@end 
+
+@implementation NSEvent (GdkQuartzNSEvent)
+- (void *)gdk_quartz_event_ref
+{
+  return _eventRef;
+}
+@end
+
 void 
 _gdk_events_init (void)
 {
@@ -1517,6 +1530,44 @@ gdk_event_translate (NSEvent *nsevent)
        */
     }
 
+  /* Special-case menu shortcut events. We create command events for
+   * those and forward to the corresponding menu.
+   */
+  if ([nsevent type] == NSKeyDown)
+    {
+      EventRef event_ref;
+      MenuRef menu_ref;
+      MenuItemIndex index;
+
+      event_ref = [nsevent gdk_quartz_event_ref];
+      if (IsMenuKeyEvent (NULL, event_ref,
+                          kMenuEventQueryOnly, 
+                          &menu_ref, &index))
+        {
+          MenuCommand menu_command;
+          HICommand hi_command;
+
+          if (GetMenuItemCommandID (menu_ref, index, &menu_command) != noErr)
+            return FALSE;
+   
+          hi_command.commandID = menu_command;
+          hi_command.menu.menuRef = menu_ref;
+          hi_command.menu.menuItemIndex = index;
+
+          CreateEvent (NULL, kEventClassCommand, kEventCommandProcess, 
+                       0, kEventAttributeUserEvent, &event_ref);
+          SetEventParameter (event_ref, kEventParamDirectObject, 
+                             typeHICommand, 
+                             sizeof (HICommand), &hi_command);
+
+          SendEventToEventTarget (event_ref, GetMenuEventTarget (menu_ref));
+
+          ReleaseEvent (event_ref);
+
+          return TRUE;
+        }
+    }
+
   nswindow = [nsevent window];
 
   /* Ignore events for no window or ones not created by GDK. */